﻿using RpcClient;
using RpcHelper;
using RpcManageClient;
using RpcModel.Model;
using Wedonek.RpcStore.Service.DAL;
using Wedonek.RpcStore.Service.Interface;
using Wedonek.RpcStore.Service.Model;

namespace Wedonek.RpcStore.Service.Collect
{
        internal class ServerLimitConfigCollect : BasicCollect<ServerLimitConfigDAL>, IServerLimitConfigCollect
        {
                private IRpcServerCollect _RpcServer => this.GetCollect<IRpcServerCollect> ();
                public ServerLimitConfig GetLimitConfig (long serverId)
                {
                        return this.BasicDAL.GetConfig (serverId);
                }
                public void DropConfig (long serverId)
                {
                        this.BasicDAL.Drop (serverId);
                        this._RpcServer.RefreshLimit (serverId);
                }

                public void SyncConfig (AddServerLimitConfig add)
                {
                        ServerLimitConfig config = this.BasicDAL.GetConfig (add.ServerId);
                        if (config == null)
                        {
                                this.BasicDAL.Add (add);
                        }
                        else if (config.IsEquals<ServerLimitConfig> (add))
                        {
                                return;
                        }
                        else
                        {
                                ServerLimitConfig set = add.ConvertMap<AddServerLimitConfig, ServerLimitConfig> ();
                                this.BasicDAL.Set (add.ServerId, set);
                        }
                        this._RpcServer.RefreshLimit (add.ServerId);

                }
        }
}
